﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.IO;
public partial class PageEdit_File : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Session["Account"] == null)
        {
            HZ.Common.log4netManager.LogFatal("文件上传", string.Format("IP {0} : 企图上传非法文件", HZ.Fun.GetClientIP()), null);
            HZ.Web.MessageBox.Show("非法上传!!!");
            Response.End();
        }
        
        if (Page.IsPostBack)
        {
            System.Web.HttpPostedFile _postFile = this.filFileUp.PostedFile;
            if (_postFile.ContentLength > 0)
            {
                string ext = Path.GetExtension(_postFile.FileName);
                ext = ext.ToLower();
                if (ext != ".xls" && ext != ".doc" && ext != ".pdf" && ext != ".rar" && ext != ".zip")
                {
                    HZ.Common.log4netManager.LogError("文件上传类型判断", string.Format("IP {0} : 上传非法类型 {1}", HZ.Fun.GetClientIP(), ext), null);
                    HZ.Web.MessageBox.Show("文件类型非法");
                    return;
                }


                string strFileName = "../UploadFile/" + SysFun.GetIntDate() + "_" + SysFun.GetIntTime() + "_" + SysFun.GetRnd(1000, 9999) + _postFile.FileName.Substring(_postFile.FileName.LastIndexOf("."));
                _postFile.SaveAs(Server.MapPath(strFileName));

                string strAlt = SysFun.ToTrim(Request.Form["txtAlt"]);

                Response.Write("<SCRIPT LANGUAGE=vbscript>\r\n");
                Response.Write("Sub window_onload\r\n");
                if (strAlt.Length > 0)
                {
                    Response.Write("window.parent.PasteHtml(\"<a href='" + strFileName + "' target='_blank'><img border='0' src='../PageEdit/ICO/" + _postFile.FileName.Substring(_postFile.FileName.LastIndexOf(".") + 1) + ".gif' width='16' height='16'> " + strAlt + "</a>\")\r\n");
                }
                else
                {
                    Response.Write("window.parent.PasteHtml(\"<a href='" + strFileName + "' target='_blank'><img border='0' src='../PageEdit/ICO/" + _postFile.FileName.Substring(_postFile.FileName.LastIndexOf(".") + 1) + ".gif' width='16' height='16'> " + _postFile.FileName.Substring(_postFile.FileName.LastIndexOf("\\") + 1) + "</a>\")\r\n");
                }
                Response.Write("window.location = \"File.aspx\"\r\n");
                Response.Write("End Sub\r\n");
                Response.Write("</SCRIPT>\r\n");
                Response.End();
            }
        }
    }
}
